package com.dcloud.exception;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class CustomExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handler(Exception e){

        if(e instanceof BizException){
            BizException bizException = (BizException)e;
            log.error("[业务异常]{}",e);
            return Result.error(Integer.parseInt(bizException.getCode()),bizException.getErrorMsg());
        }else {
            log.error("[系统异常]{}",e);
            return Result.error("系统异常");
        }

    }

}
